# Contributor: Ivan Tham <pickfire@riseup.net>
# Maintainer: Nero <nero@w1r3.net>
pkgname=tlp
_pkgname=TLP
pkgver=1.3.1
pkgrel=3
pkgdesc="Linux Advanced Power Management"
url="https://linrunner.de/en/tlp/tlp.html"
arch="noarch"
license="GPL-2.0-or-later"
options="!check"  # no test suite
depends="perl util-linux" # /usr/share/tlp/tlp-readconfs uses perl (see #11181)
makedepends="coreutils"
subpackages="$pkgname-doc $pkgname-rdw:rdw $pkgname-bash-completion:bashcomp $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/linrunner/$_pkgname/archive/$pkgver.tar.gz
	$pkgname.initd"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	make
}

package() {
	make TLP_WITH_SYSTEMD=0 DESTDIR="$pkgdir" install-tlp

	install -dm755 "$pkgdir"/usr/share/man/man1
	install -m644 man/*.1 "$pkgdir"/usr/share/man/man1
	install -dm755 "$pkgdir"/usr/share/man/man8
	install -m644 man/*.8 "$pkgdir"/usr/share/man/man8
	install -m755 "$srcdir"/tlp.initd "$pkgdir"/etc/init.d/$pkgname
}

rdw() {
	pkgdesc="Linux Advanced Power Management - Radio Device Wizard"
	depends="tlp"

	cd "$builddir"
	make DESTDIR="$subpkgdir" install-rdw
}

bashcomp() {
	pkgdesc="Bash completions for $pkgname"
	depends=""
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	mkdir -p "$subpkgdir"/usr/share
	mv "$pkgdir"/usr/share/bash-completion "$subpkgdir"/usr/share
}

sha512sums="7ebb14ea797ad8aae613c537de51107a3c7430b5c6ee1407e722e2069ed5376f88ab3dac613651fafabd92d219b980452f236bef33e8a655b1abbfed5eded1b1  tlp-1.3.1.tar.gz
e6de216b2540413812711b3304cdc29c8729d527080cfd747ba382db50166dd21c6c27ff467f9f2a967e92007c7a311b00e88262952c34a22f417578c66cf4e7  tlp.initd"
